<?php
require_once 'classes/Login.php';
require_once 'classes/JobPost.php';
$Login = new Login;
$JobPost = new JobPost;
if(!$Login->verify())
{
    header('Location:index.php');
}
$companyName = $Login->getCompanyName($_SESSION['employerID']);
$jobPosts = $JobPost->getEmployerPosts($_SESSION['employerID']);
$expiredPosts = $JobPost->getExpiredEmployerPosts($_SESSION['employerID']);
include 'includes/header.inc.php';
?>
<h2>Active Job Posts</h2>

<script language="JavaScript">
function verifyDelete()
{
 return confirm('You sure you want to remove this job post?');
}
function verifyRepost()
{
 return confirm('You sure you want to repost this job post?');
}
</script>

<?php
if(!empty($jobPosts))
{
    echo '        <table class="postingsTable">
                        <thead>
                            <tr>
                                <th scope="col" id="postDate">Date</th>
                                <th scope="col" id="postTitle">Title</th>
                                <th scope="col" id="viewPost">View</th>
                                <th scope="col" id="editPost">Edit</th>
                                <th scope="col" id="deletePost">Delete</th>
                            </tr>
                        </thead>
                        <tbody>';
    for($i=0;$i<count($jobPosts);$i++)
    {
        $date = strtotime($jobPosts[$i]['postDate']);
        echo '
                            <tr>
                                <td class="jobDate">'.date("m/d/y", $date).'</td>
                                <td class="jobTitle">'.$jobPosts[$i]['title'].'</td>
                                <td class="jobActions"><a href="/sandbox1/viewJobPostBasic.php?jobID='.$jobPosts[$i]['id'].'" id="viewPost'.$jobPosts[$i]['id'].'" class="viewPost"><img src="/sandbox1/media/images/view.png" alt="View Post '.$jobPosts[$i]['id'].'"/></a></td>
                                <td class="jobActions"><a href="javascript:void(0);" id="editPost'.$jobPosts[$i]['id'].'" class="editPost"><img src="/sandbox1/media/images/edit.png" alt="Edit Post '.$jobPosts[$i]['id'].'"/></a></td>
                                <td class="jobActions"><a href="userProcess.php?action=removeOnePost&id='.$jobPosts[$i]['id'].'" onclick="return verifyDelete()"><img src="/sandbox1/media/images/delete.png" title="Delete This Post"/></a></td>
                            </tr>';
    }
     echo'               </tbody>
                    </table>';
}
else
{
    echo '<div id="noResults">You currently have no active job posts.</div>';
}

echo '<hr>';
echo '<h2>Expired Job Posts</h2>';
if(!empty($expiredPosts))
{
    echo '          <table class="postingsTable">
                        <thead>
                            <tr>
                                <th scope="col" id="postDate">Date</th>
                                <th scope="col" id="postTitle">Title</th>
                                <th scope="col" id="viewPost">View</th>
                                <th scope="col" id="repostJob">Repost</th>
                            </tr>
                        </thead>
                        <tbody>';
    for($i=0;$i<count($expiredPosts);$i++)
    {
        $date = strtotime($expiredPosts[$i]['postDate']);
        echo '
                            <tr>
                                <td class="jobDate">'.date("m/d/y", $date).'</td>
                                <td class="jobTitle">'.$expiredPosts[$i]['title'].'</td>
                                <td class="jobActions">
                                    <a href="/sandbox1/viewJobPost.php?jobID='.$expiredPosts[$i]['id'].'" id="viewPost'.$expiredPosts[$i]['id'].'" class="viewPost">
                                            <img src="/sandbox1/media/images/view.png" alt="View Post '.$expiredPosts[$i]['id'].'"/>
                                    </a>
                                </td>
                                <td class="jobActions">
                                    <a href="/sandbox1/userProcess.php?action=RepostJob&postId='.$expiredPosts[$i]['id'].'" onclick="return verifyRepost()">
                                        <img src="/sandbox1/media/images/repost.png" alt="Re-Post '.$expiredPosts[$i]['id'].'"/>
                                    </a>
                                </td>
                            </tr>';
    }
     echo'               </tbody>
                    </table>';
}
else
{
    echo '<div id="noResults">You have no expired Job Posts.</div>';
}



include 'includes/footer.inc.php';
?>